package sudoku.app;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Paint.Style;
import android.os.Parcelable;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;

public class ZoomView extends View{

	private int viewSideLength;
	private Paint outerPaint;
	private Paint cellPaint;
	private int cellLength;

	public ZoomView(Context context, AttributeSet attrs) {
		super(context, attrs);
		// TODO Auto-generated constructor stub
	}
	
	public ZoomView(Context context){
		super(context);
	}

	@Override
	protected void onDraw(Canvas canvas) {
		cellLength = viewSideLength/3;
		setOuterPaint();
		drawOuter(canvas);
		setCellPaint();
		drawCell(canvas);
	}

	private void drawCell(Canvas canvas) {
		//Draw 2 vertical lines
		for (int i=1; i<3; i++){
			canvas.drawRect(i*cellLength, 0, i*cellLength, viewSideLength, cellPaint);
		}
		//Draw 2 horizontal lines
		for (int i=1; i<3; i++){
			canvas.drawRect(0, i*cellLength, viewSideLength, i*cellLength, cellPaint);
		}
	}

	private void setCellPaint() {
		cellPaint = new Paint();
		cellPaint.setColor(Color.BLACK);
		cellPaint.setStyle(Style.STROKE);
		cellPaint.setStrokeWidth(1);
	}

	private void setOuterPaint() {
		outerPaint = new Paint();
		outerPaint.setColor(Color.WHITE);
		outerPaint.setStyle(Style.FILL);
	}

	private void drawOuter(Canvas canvas) {
		canvas.drawRect(0, 0, viewSideLength, viewSideLength, outerPaint);
	}

	@Override
	protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
		int widthSize = MeasureSpec.getSize(widthMeasureSpec);
		int heightSize = MeasureSpec.getSize(heightMeasureSpec);
				
		if (widthSize < heightSize){
			viewSideLength = widthSize;
		} else {
			viewSideLength = heightSize;
		}
		setMeasuredDimension(viewSideLength, viewSideLength);
	}

	@Override
	protected void onRestoreInstanceState(Parcelable state) {
		// TODO Auto-generated method stub
		super.onRestoreInstanceState(state);
	}

	@Override
	protected Parcelable onSaveInstanceState() {
		// TODO Auto-generated method stub
		return super.onSaveInstanceState();
	}

	@Override
	public boolean onTouchEvent(MotionEvent event) {
		// TODO Auto-generated method stub
		return super.onTouchEvent(event);
	}
	
	

}
